﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DBBase;

namespace Business
{
    public partial class xnzpForm1 : Form
    {
        public xnzpForm1(string slsh, string hphm, string hpzl)
        {
            InitializeComponent();
            slsh1 = slsh;
            shphm = hphm;
            shpzl = hpzl;
        }
        public string slsh1;
        public string shphm;
        public string shpzl;
        public void getpicdata(string lsh, string szd, PictureBox pic)
        {
            Query mquery = new Query();
            string sql;
            sql = string.Format(@"Select * from ZBZLPhoto Where jylsh='{0}'", lsh);
            DataTable dt = mquery.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                byte[] content;
                if (dt.Rows[0][szd].ToString().Length > 10)
                {
                    content = (byte[])dt.Rows[0][szd];
                    if (content.Length > 10)
                    {
                        string base64 = Convert.ToBase64String(content);
                        //流数据写到控件上
                        System.IO.MemoryStream ms = new System.IO.MemoryStream(content);
                        //通过流对象建立Bitmap
                        System.Drawing.Bitmap bmp = new Bitmap(ms);
                        //this.pictureIC.Image = bmp;
                        Point ptLoction = new Point(bmp.Size);
                        if (ptLoction.X > pic.Size.Width || ptLoction.Y > pic.Size.Height)
                        {
                            //圖像框的停靠方式   
                            //圖像充滿圖像框，並且圖像維持比例   
                            pic.SizeMode = PictureBoxSizeMode.Zoom;
                        }
                        else
                        {
                            //圖像在圖像框置中   
                            pic.SizeMode = PictureBoxSizeMode.CenterImage;
                        }
                        pic.Image = bmp;
                    }
                }
                else
                {
                    pic.Image = null;
                }
            }
            else
            {
                pic.Image = null;
            }
        }
        private void xnzpForm1_Load(object sender, EventArgs e)
        {

        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {

            if (radioButton1.Checked)
            {
                radioButton2.Checked = false;
                radioButton3.Checked = false;
                getpicdata(slsh1, "donglixing", pic_gw);
            } 
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {

            if (radioButton2.Checked)
            {
                radioButton1.Checked = false;
                radioButton3.Checked = false;
                getpicdata(slsh1, "zhidong", pic_gw);
            } 
        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {

            if (radioButton3.Checked)
            {
                radioButton2.Checked = false;
                radioButton1.Checked = false;
                getpicdata(slsh1, "dengguang", pic_gw);
            } 
        }

        private void pic_gw_Click(object sender, EventArgs e)
        {
            photoform f = new photoform();
            f.pictureBox1.Image = pic_gw.Image;
            f.ShowDialog();
        }
    }
}
